<div class="row">
	<div class="col-md-12">
		<ol class="breadcrumb">
			<li>
				<a href="#" onclick="toHome()">
					主页
				</a>
			</li>
			<li>
				<a href="#" class="toList" onclick="toTaiMovie()">
					太影达人
				</a>
			</li>
			<li class="active">
				添加
			</li>
		</ol>
	</div>
</div>
<form role="form" class="form-horizontal">
	<div class="row page-cont">
		<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 cont-top">
			<div class="panel panel-white">
				<div class="panel-heading">
					<h4 class="panel-title">
						<span class="title-text">录入</span>
					</h4>
					<div class="panel-tools">
						<div class="dropdown">
							<a data-toggle="dropdown" class="btn btn-xs dropdown-toggle btn-transparent-grey">
								<i class="fa fa-cog"></i>
							</a>
							<ul class="dropdown-menu dropdown-light pull-right" role="menu">
								<li>
									<a class="panel-collapse collapses" href="#"><i class="fa fa-angle-up"></i> <span>折叠</span> </a>
								</li>
								<li>
									<a class="panel-expand" href="#">
										<i class="fa fa-expand"></i> <span>全屏</span>
									</a>
								</li>
							</ul>
						</div>
						<a class="btn btn-xs btn-link panel-close" href="#">
							<i class="fa fa-times"></i>
						</a>
					</div>
				</div>
				<div class="panel-body">
					<div class="body-cont">
						<div class="newCard">
						  	<div class="form-group panel-cont">
							    <label class="col-sm-2 control-label">图片</label>
							    <div class="col-sm-5 uploadImg">
							    	<div>选择文件</div>
							      	<input type="file" class="form-control" id="topImg" />
							    </div>
							    <span class="col-sm-4 tips">
							    	<i class="fa fa-info-circle"></i>
							    	类型为 gif,jpg,jpeg,bmp,png
							    </span>
						  	</div>
						  	<div class="form-group panel-cont">
							    <label class="col-sm-2 control-label">图片预览</label>
							    <div class="col-sm-5 imgShow">
							    	
							    </div>
						  	</div>
						  	<div class="form-group panel-cont">
							    <label class="col-sm-2 control-label">月份</label>
							    <div class="col-sm-5">
							   		<input type='text' class="form-control" id="fill-mouth" />
							    </div>
								<span class="col-sm-4 tips">
							    	<i class="fa fa-info-circle"></i>
							    	请填写月份
							    </span>								    
						  	</div>
							<div class="form-group panel-cont">
							    <label class="col-sm-2 control-label">电影名称</label>
							    <div class="col-sm-5">
							   		<input type='text' class="form-control" id="movieName" />
							    </div>							    
						  	</div>						  	
							<div class="form-group panel-cont">
							    <label class="col-sm-2 control-label">电影评分</label>
							    <div class="col-sm-5">
							   		<input type='text' class="form-control" id="movieScore" />
							    </div>							    
						  	</div>						  	
						</div>						
					</div>
				  	<div class="form-group panel-btn">
				  		<div class="col-sm-2 col-sm-offset-3">
				  			<button type="button" class="btn btn-danger submit-btn">提交&nbsp;<i class="fa fa-arrow-circle-right"></i></button>
				  		</div>
				  	</div>
				</div>
			</div>
		</div>
	</div>
</form>
<script>
	/**************************************变量********************************************/
	var username = GetQueryString("username");      // 用户姓名
	var token = MXCookie.get("token",token);  // 登陆token 
	
	/**************************************事件********************************************/
	addUploadImg();	 // 上传图片

	datePicker($("#chooseDate"));    // 时间

	// 提交
	$(".submit-btn").click(function(){
		if(msgCheck()){
			var baseCode = $(".imgShow img").attr("src").split(",")[1];
			var type =  $("#fill-mouth").val();			
			submitData(baseCode,type);
		}
	});
	/**********************************************函数**********************************************/


	// 信息验证
	function msgCheck(){
		var regstr = /^(?:1[0-2]|[1-9])$/;
		if(!$(".imgShow img").attr("src")){
			tips("选择图片");
			return false;
		}else if($("#fill-mouth").val() == ""){
			tips("请填写月份");
			$(this).focus();
			return false;
		}else if($("#fill-mouth").val() != "" && !regstr.test($("#fill-mouth").val())){
			tips("请输入1到12的正整数");
			$(this).focus();
		}else if($("#movieName").val() == ""){
			tips("请填写电影名称");
			$(this).focus();			
		}else if($("#movieScore").val() == ""){
			tips("请填写电影评分");
			$(this).focus();			
		}else{
			return true;
		}
	}

	// 新增
	function submitData(baseCode,type){
		$.ajax({
			url: localStorage.grobalUrl + "/man/updataImg",
			type: "post",
			data:{
				username: GetQueryString("username"),
				token: token,	
				baseCode:baseCode,
				type: type,
				name: $("#movieName").val(),
				score: $("#movieScore").val()
			},
			success: function(data){
				console.log(data);
				if(data.errCode == "00005"){
					tips("请重新登陆");
					setTimeout(function(){
						window.location.href = "login_login.html";
					},500);					
				}else if(data.errCode == "00000"){
					getPage("view/taiMovie/list.html");
				}else{
					tips("添加失败");
				}
			},
			error: function(error){
				console.log(error);
			}
		});
	}
	
</script>
